from django.db import models
from user.models import User
# Create your models here.


# 商品表
class Goods(models.Model):
    name = models.CharField(max_length=255, verbose_name='商品名称')
    price = models.CharField(max_length=255, verbose_name='商品价格')
    image = models.CharField(max_length=255, verbose_name='商品图片')
    good_review = models.IntegerField(verbose_name='好评数量')
    mixed_review = models.IntegerField(verbose_name='中评数量')
    bad_review = models.IntegerField(verbose_name='差评数量')
    views = models.IntegerField(verbose_name='浏览量')
    sales = models.IntegerField(verbose_name='销量')
    is_show = models.BooleanField(default=True, verbose_name='是否展示')
    desc = models.TextField(verbose_name='商品描述', blank=True, null=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'goods'


# 评价表
class Message(models.Model):
    content = models.CharField(max_length=255, verbose_name='留言内容')
    img = models.CharField(max_length=255, verbose_name='留言图片', blank=True, null=True)
    is_show = models.BooleanField(default=True, verbose_name='是否展示')
    status = models.CharField(max_length=255, verbose_name='留言状态', choices=((0, '未审核'), (1, '已审核')), default=1)
    evaluate = models.CharField(max_length=255, verbose_name='留言评价', choices=((0, '差评'), (1, '中评'), (2, '好评')))
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户id')
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name='商品id')

    def __str__(self):
        return self.content

    class Meta:
        db_table = 'message'


# 套餐列表
class Combo(models.Model):
    name = models.CharField(max_length=255, verbose_name='套餐名称')
    price = models.CharField(max_length=255, verbose_name='套餐价格')

    class Meta:
        db_table = 'combo'


# 中间表
class Middle(models.Model):
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name='商品id')
    combo = models.ForeignKey(Combo, on_delete=models.CASCADE, verbose_name='套餐id')

    class Meta:
        db_table = 'middle'


class Message2(models.Model):
    content = models.TextField(verbose_name='评论内容')
    parent = models.ForeignKey('self', on_delete=models.CASCADE, verbose_name='父级评论id', blank=True, null=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户id')
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name='商品id')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', blank=True, null=True)  # 评论创建时间

    class Meta:
        db_table = 'message2'


